﻿using System;
using System.Configuration;
using mojoPortal.Net;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
using System.IO;
using Brettle.Web.NeatUpload;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace ud_gSDMS.Member
{
    public partial class UpdateLoaiCB : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;
        private SiteUser _siteUser;
        protected String cacheDependencyKey;
        DBQLNS _respository=new DBQLNS();
        
        void Page_Load(object sender, EventArgs e)
        {
            _siteUser = SiteUtils.GetCurrentSiteUser();
            if (_siteUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            }

            if (!Page.IsPostBack)
            {
                PopulateLabels();
                PopulateControls();
            }
        }
        private void PopulateLabels()
        {
            LoaiCBTest child1 = new LoaiCBTest("1", "0298", "Nguyễn Lê Nguyên Ngữ", "CH", "Cơ Hữu", "Ban Giám Hiệu", "", "");
            LoaiCBTest child2 = new LoaiCBTest("2", "0298", "Trần Thu Hằng", "CH", "Cơ Hữu", "Ban Giám Hiệu", "", "");
            LoaiCBTest child3 = new LoaiCBTest("3", "0298", "Lưu Bích Phượng", "CH", "Cơ Hữu", "Ban Giám Hiệu", "", "");
            List<LoaiCBTest> lst = new List<LoaiCBTest>();
            lst.Add(child1);
            lst.Add(child2);
            lst.Add(child3);
            Session["LoaiCB"] = lst;
        }
        private void BindData()
        {
            gvChildInfo.DataSource = Session["LoaiCB"];
            gvChildInfo.DataBind();
        }

        private void PopulateControls()
        {
            BindData();
        }
        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            SuppressPageMenu();
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
            cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
        }

        private void LoadPanels()
        {
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion

        protected void gvChildInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvChildInfo.EditIndex = e.NewEditIndex;
            BindData();
        }

        protected void gvChildInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List<LoaiCBTest> l = (List<LoaiCBTest>)Session["LoaiCB"];
            TextBox txt_maso = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt1");
            TextBox txt_hoten = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt2");
            TextBox txt_loai = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt3");
            TextBox txt_dgloaicb = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt4");
            TextBox txt_tendv = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt5");
            TextBox txt_luong = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt6");
            TextBox txt_nghi = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt7");
            
            string tam = l[e.RowIndex].ID;
            LoaiCBTest news = new LoaiCBTest(tam, txt_maso.Text, txt_hoten.Text, txt_loai.Text, txt_dgloaicb.Text, txt_tendv.Text, txt_luong.Text, txt_nghi.Text);
            l[e.RowIndex] = news;
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<LoaiCBTest> l = (List<LoaiCBTest>)Session["LoaiCB"];
            l.RemoveAt(e.RowIndex);
            BindData();
        }
    }

    public class LoaiCBTest
    {
        public string ID { get; set; }
        public string MaSo { get; set; }
        public string HoTen {get ; set;}
        public string Loai{ get; set; }
        public string DGloaiCB { get; set; }
        public string TenDV { get; set; }
        public string Luong { get; set; }
        public string Nghi { get; set; }
        public LoaiCBTest(string id, string maso, string hoten, string loai, string DGloaiCB, string TenDV, string Luong, string Nghi)
        {
            this.ID = id;
            this.MaSo = maso;
            this.HoTen = hoten;
            this.Loai = loai;
            this.DGloaiCB = DGloaiCB;
            this.TenDV = TenDV;
            this.Luong = Luong;
            this.Nghi = Nghi;
        }
    }

    
}